package com.dys.controller;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.InternalResourceView;
import org.springframework.web.servlet.view.RedirectView;

/**
 * @className: com.dys.controller.ModelAndViewController
 * @description: SpringMVC_ModelAndView
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/10/26 22:49
 */
@Controller
public class ModelAndViewController {

    @RequestMapping("/getModelAndViewByForward")
    public ModelAndView getModelAndViewByForward() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("forward:/modelAndViewForward.jsp");
        System.out.println("ModelAndView请求转发实现......");
        return mv;
    }

    @RequestMapping("/getModelAndViewByForward2")
    public ModelAndView getModelAndViewByForward2() {
        ModelAndView mv = new ModelAndView();
        mv.setView(new InternalResourceView("/modelAndViewForward.jsp"));
        System.out.println("ModelAndView请求转发实现2......");
        return mv;
    }

    @RequestMapping("/getModelAndViewByRedirect")
    public ModelAndView getModelAndViewByRedirect() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("forward:/modelAndViewRedirect.jsp");
        System.out.println("ModelAndView响应重定向实现......");
        return mv;
    }

    @RequestMapping("/getModelAndViewByRedirect2")
    public ModelAndView getModelAndViewByRedirect2(HttpServletRequest request) {
        ModelAndView mv = new ModelAndView();
        mv.setView(new RedirectView(request.getContextPath() + "/modelAndViewRedirect.jsp"));
        System.out.println("ModelAndView实现响应重定向2......");
        return mv;
    }
}
